package com.动态加载.handle;

import com.动态加载.constat.GirlEnum;
import com.动态加载.constat.SupperGirlEnum;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class GirlHandleAdapter implements ApplicationContextAware {
    Map<SupperGirlEnum,GirlHandle> girlMap = new HashMap<>();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String,GirlHandle> map = applicationContext.getBeansOfType(GirlHandle.class);
        for(GirlHandle girlHandle:map.values()){
            girlMap.put(girlHandle.girlType(),girlHandle);
            System.out.println(girlHandle.girlType().name());
        }
    }

    public String query(Integer girl) {
        GirlEnum girlEnum = GirlEnum.getGirlType(girl);
        SupperGirlEnum supperGirlEnum =  girlEnum.getSupperGirlEnum();

        return girlHandle(supperGirlEnum).query(girl);
    }
    public GirlHandle girlHandle(SupperGirlEnum supperGirlEnum){
        return girlMap.get(supperGirlEnum);
    }
}
